<template>
  <div class="rateQuery">
    <div v-if="feeTypeName" style="margin-left:12vw">
      <h3 style="font-size: 14px;">
        模板类型：{{ feeTypeName }}
        <span style="margin-left:30%">模板名称：{{ feename }}</span>
      </h3>
    </div>
    <a-form @submit="handleSubmit" :form="form" style="margin:0 auto;">
      <div style="width: 90%;margin:20px auto;">
      
        <mer-rate :MerRateList="MerRateList" ref="getMerRateData"></mer-rate>

        <a-form-item v-bind="formItemLayout" label="设为默认">
          <a-select
            style="width:60%"
            :disabled="disabled"
            v-model="defaultValue"
            placeholder="设为默认"
          >
            <a-select-option value="true">是</a-select-option>
            <a-select-option value="false">否</a-select-option>
          </a-select>
        </a-form-item>
      </div>

      <div class="ratebutton">
        <a-button
          style="width:90px;margin-top:1vh;"
          html-type="submit"
          type="primary"
          >保存</a-button
        >
        <!-- <a-button
          style="width:90px;margin-top:1vh;margin-left:20px;"
          @click="goback"
          type="primary"
        >取消</a-button>-->
      </div>
    </a-form>
  </div>
</template>
<script>
import MerRate from "../../common/MerRate";
export default {
  components: {
    MerRate
  },
  data() {
    return {
      MerRateList:null,
      feeType: "请选择",
      defaultValue: "true",
      disabled:false,
      feeName: "",
      queryid: "",
      feeTypeName: "",
      feename: "",
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 20 },
          md: { span: 16 }
        }
      }
    };
  },
  activated() {
    this.queryid = this.$route.params.id;
    // this.feeTypeName = this.$route.params.feeTypeName;
    // this.feename = this.$route.params.name;
    this.getratelist();
  },
  mounted() {
    //   this.spinning = true;
  },

  methods: {
    goback() {
      this.$router.push("/org/transmanage/rateTemplate");
    },
    getratelist() {
      this.$axios.get("/agent/fee/group/getById/" + this.queryid).then(res => {
        console.log("rate", res);
        if (res.data.code == "OK") {
          this.MerRateList = res.data.data.feeTemplateDTOMap;
          this.feeTypeName = res.data.data.feeTypeName;
          this.feename = res.data.data.name;
          
          this.disabled = res.data.data.defaultValue
          if(this.disabled){
            this.defaultValue = "true"
          }else{
            this.defaultValue = "false"
          }


        } else {
          // this.spinning=false;
        }
      });
    },
    onChange2(e) {
      console.log("radio checked", e.target.value);
      console.log("radio checked", e.target.name);
      let index = Number(e.target.name);
      if (e.target.value == "true") {
        this.ratelist[index].status = true;
      } else {
        this.ratelist[index].status = false;
      }
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          
          this.$refs.getMerRateData.rateConversion()

          if(this.$refs.getMerRateData.feeTemplateList.length == 0){
            console.log("数组为0")
            return false
          }
          // console.log("通过",this.$refs.getMerRateData.feeTemplateList)
          let feeTemplateUpdateRequests = this.$refs.getMerRateData.feeTemplateList

          if (this.defaultValue == "true") {
            this.defaultValue = true;
          } else {
            this.defaultValue = false;
          }
          // console.log(feeTemplateUpdateRequests);
          // console.log(this.defaultValue);

          this.$axios
            .post("/agent/fee/group/updateFeeTemplateGroup", {
              id: this.queryid,
              name: values.feename,
              defaultValue: this.defaultValue,
              feeTemplateUpdateRequests: feeTemplateUpdateRequests
            })
            .then(res => {
              console.log(res);
              if (res.data.code == "OK") {
                this.$router.push("/org/transmanage/rateTemplate");
              } else {
                this.$message.warning(res.data.message);
              }
            });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
/deep/.noExpand {
  .ant-table-row-expand-icon {
    display: none;
  }
}
.rateQuery {
  overflow: scroll;
  height: 100%;
  // padding: 30px;
  overflow-x: hidden;
  overflow-y: auto;
}
/*滚动条样式*/
.rateQuery::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 4px;
  /*高宽分别对应横竖滚动条的尺寸*/
  height: 4px;
}

.rateQuery::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 5px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: rgba(0, 0, 0, 0.2);
}

.rateQuery::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.1);
}
.ratebutton {
  text-align: center;
}
</style>
